
const defaultState = {
    connected: false
};

/**
 * 连接 WebSocket 服务
 * @type {String}
 */
export const CONNECT_WEBSOCKET = 'CONNECT_WEBSOCKET';

/**
 * 重新连接 WebSocket 服务
 * @type {String}
 */
export const RECONNECT_WEBSOCKET = 'RECONNECT_WEBSOCKET';

/**
 * 连接 WebSocket 服务
 * @type {String}
 */
export const WEBSOCKET_CONNECTED = 'WEBSOCKET_CONNECTED';

/**
 * 连接 WebSocket 服务中
 * @type {String}
 */
export const WEBSOCKET_CONNECTING = 'WEBSOCKET_CONNECTING';

/**
 * 中断 WebSocket 服务
 * @type {String}
 */
export const WEBSOCKET_DISCONNECTED = 'WEBSOCKET_DISCONNECTED';

/**
 * WebSocket 错误信息
 * @type {String}
 */
export const WEBSOCKET_ERROR = 'WEBSOCKET_ERROR';

/**
 * WebSocket Connection Reducer
 * @param {Object} state
 * @param {Object} action
 */
export default function webSocketConn(state = defaultState, action) {
    switch (action.type) {
        case WEBSOCKET_CONNECTED:
            return {
                ...state,
                connected: true
            };
        case WEBSOCKET_DISCONNECTED:
            return {
                ...state,
                connected: false
            };
        default:
            return state;
    }
}